﻿using Max.PH5_2006.ShoppingSite.Domain;
using Max.PH5_2006.ShoppingSite.DTO;
using Max.PH5_2006.ShoppingSite.IService;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Max.PH5_2006.ShoppingSite.API.Controllers
{
    [Route("city")]
    [ApiController]
    public class CityController : ControllerBase
    {
        readonly ICityService _service;

        public CityController(ICityService service)
        {
            _service = service;
        }

        [HttpGet]
        public IActionResult Query(string? name="")
        {
            ResponseResultDto result = new();


            System.Linq.Expressions.Expression<Func<CityEntity, bool>> where = null;
            where = x => x.Name.Contains(name ?? "");

            var list = _service.Query(where);

            return Ok(list);
        }


        [HttpGet("list")]
        public IActionResult QueryCity(string id)
        {
            ResponseResultDto response = new();

            var data = _service.Query().Where(x => id.Equals(x.PId.ToString())).ToList();
            
            response.Data = data;
            
            return Ok(response);
        }
    }
}
